#include <iostream>

using namespace std;
bool P(int num)
{
    if (num <= 1)
        return false;
    for (int i = 2; i * i <= num; ++i)
    {
        if (num % i == 0)
            return false;
    }
    return true;
}

int f(int num)
{
    int s = num - 1;
    int l = num + 1;

    while (true)
        {
        if (P(s))
        {
            return s;
        } else if (P(l))
        {
            return l;
        }
        s--;
        l++;
        }
}
int main()
{

    int razryad = 0;
    string s, s1;
    getline(cin,s);
    int spaces = 0;
    int spaces1 = 0;
    int N = s.size();
    for(int i = 0; i < N; i++){
        if(s[i] == ' ')
            spaces += 1;
    }
    int chislo = 0;
    for(int i = 0;i < N; i++){
        if(spaces1 == spaces){
            s1 = s.substr(0);
            if(s1 == "one")
                chislo += 1;
            if(s1 == "two")
                chislo += 2;
            if(s1 == "three")
                chislo += 3;
            if(s1 == "four")
                chislo += 4;
            if(s1 == "five")
                chislo += 5;
            if(s1 == "six")
                chislo += 6;
            if(s1 == "seven")
                chislo += 7;
            if(s1 == "eight")
                chislo += 8;
            if(s1 == "nine")
                chislo += 9;
            break;
        }
        if(s[i] == ' '){
            razryad++;
            spaces1 += 1;
            s1 = s.substr(0,i);
            s = s.erase(0,i+1);
            i = 0;
            if(razryad == 1){
                if(s1 == "one")
                    chislo += 100;
                if(s1 == "two")
                    chislo += 200;
                if(s1 == "three")
                    chislo += 300;
                if(s1 == "four")
                    chislo += 400;
                if(s1 == "five")
                    chislo += 500;
                if(s1 == "six")
                    chislo += 600;
                if(s1 == "seven")
                    chislo += 700;
                if(s1 == "eight")
                    chislo += 800;
                if(s1 == "nine")
                    chislo += 900;
                }
            if(razryad == 2){
                if(s1 == "one")
                    chislo += 10;
                if(s1 == "two")
                    chislo += 20;
                if(s1 == "three")
                    chislo += 30;
                if(s1 == "four")
                    chislo += 40;
                if(s1 == "five")
                    chislo += 50;
                if(s1 == "six")
                    chislo += 60;
                if(s1 == "seven")
                    chislo += 70;
                if(s1 == "eight")
                    chislo += 80;
                if(s1 == "nine")
                    chislo += 90;
            }
        }
    }
    int result = f(chislo);
    cout << result;
}
